import { Component, OnInit } from '@angular/core';
import { FreeflowService } from '../freeflow.service';
import { MdlSnackbarService } from '@angular-mdl/core';
import { DynamicDialogRef, DynamicDialogConfig } from 'primeng/primeng';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';

@Component({
    templateUrl: './fftranset-attr.component.html',
    styleUrls: ['./fftranset-attr.component.scss'],
    providers: []
})
export class FfTransetAttrComponent implements OnInit {
    transId: number;
    transetAttrForm: FormGroup;
    transet: any = {};
    constructor(private fb: FormBuilder,
        private freeflowService: FreeflowService,
        private mdlSnackbarService: MdlSnackbarService,
        public ref: DynamicDialogRef, 
        public config: DynamicDialogConfig) {
        this.transId  = this.config.data.transId;
    }

    ngOnInit() {
        this.freeflowService.loadProcTrans(this.transId).subscribe(data => {
            this.transet = data;
            this.buildForm();
        });
        this.buildForm();
     }

    save(){
        this.freeflowService.updateProcTrans(this.transetAttrForm.value).subscribe(data=>{
            this.ref.close(data);
            this.mdlSnackbarService.showToast("节点属性信息保存成功");
        });
    }

    cancel(){
        this.ref.close();
    }

    buildForm(): void {
        this.transetAttrForm = this.fb.group({
            'transId': [this.transet.transId],
            'fromAct': [this.transet.fromAct],
            'fromActName': [this.transet.fromActName],
            'toAct': [this.transet.toAct],
            'toActName': [this.transet.toActName],
            'transName': [this.transet.transName],
            'filterSql': [this.transet.filterSql]
        });
    }
 
}
